package android.framework.rpc;

import java.io.IOException;

public class DefaultProtocolManager<TSendingValue> implements IProtocolManager<TSendingValue>{

	private ISender<TSendingValue> sender;
	
	public DefaultProtocolManager(ISender<TSendingValue> sender, ServerDetails serverDetails){
		this.sender = sender;
		sender.init(serverDetails);
	}
	
	public TSendingValue sendNewRequest(Request<TSendingValue> request) throws RuntimeException{
		try {
			//TODO: make it async and use thread from the thread-pool
			TSendingValue result = sender.send(request.getData());
			return result;
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

}
